home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_005 / speech.demo / createextio.c next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  147 lines

  1. /*
  2.  *
  3.  *    DISCLAIMER:
  4.  *
  5.  *    This program is provided as a service to the programmer
  6.  *    community to demonstrate one or more features of the Amiga
  7.  *    personal computer.  These code samples may be freely used
  8.  *    for commercial or noncommercial purposes.
  9.  * 
  10.  *     Commodore Electronics, Ltd ("Commodore") makes no
  11.  *    warranties, either expressed or implied, with respect
  12.  *    to the program described herein, its quality, performance,
  13.  *    merchantability, or fitness for any particular purpose.
  14.  *    This program is provided "as is" and the entire risk
  15.  *    as to its quality and performance is with the user.
  16.  *    Should the program prove defective following its
  17.  *    purchase, the user (and not the creator of the program,
  18.  *    Commodore, their distributors or their retailers)
  19.  *    assumes the entire cost of all necessary damages.  In 
  20.  *    no event will Commodore be liable for direct, indirect,
  21.  *    incidental or consequential damages resulting from any
  22.  *    defect in the program even if it has been advised of the 
  23.  *    possibility of such damages.  Some laws do not allow
  24.  *    the exclusion or limitation of implied warranties or
  25.  *    liabilities for incidental or consequential damages,
  26.  *    so the above limitation or exclusion may not apply.
  27.  *
  28.  */
  29.  
  30. /***********************************************************************
  31. *
  32. *    Exec Support Function -- Extended IO Request
  33. *
  34. ***********************************************************************/
  35.  
  36. #include "exec/types.h"
  37. #include "exec/nodes.h"
  38. #include "exec/lists.h"
  39. #include "exec/memory.h"
  40. #include "exec/interrupts.h"
  41. #include "exec/ports.h"
  42. #include "exec/libraries.h"
  43. #include "exec/io.h"
  44. #include "exec/tasks.h"
  45. #include "exec/execbase.h"
  46.  
  47. extern APTR AllocMem();
  48.  
  49. /****** exec_support/CreateExtIO **************************************
  50. *
  51. *   NAME    
  52. *    CreateExtIO() -- create an Extended IO request
  53. *
  54. *   SYNOPSIS
  55. *    ioReq = CreateExtIO(ioReplyPort,size);   
  56. *
  57. *   FUNCTION
  58. *    Allocates memory for and initializes a new IO request block
  59. *    of a user-specified number of bytes.
  60. *
  61. *   INPUTS
  62. *    ioReplyPort - a pointer to an already initialized
  63. *        message port to be used for this IO request's reply port.
  64. *
  65. *   RESULT
  66. *    Returns a pointer to the new block.  Pointer is of the type
  67. *    struct IORequest.
  68. *
  69. *    0 indicates inability to allocate enough memory for the request block
  70. *    or not enough signals available.
  71. *
  72. *   EXAMPLE
  73. *    struct IORequest *myBlock;
  74. *    if( (myBlock = CreateExtIO(myPort,sizeof(struct IOExtTD)) == NULL)
  75. *        exit(NO_MEM_OR_SIGNALS);
  76. *
  77. *    example used to allocate space for IOExtTD (trackdisk driver
  78. *    IO Request block for extended IO operations).
  79. *
  80. *   SEE ALSO
  81. *    DeleteExtIO
  82. *
  83. ***********************************************************************/
  84.  
  85. struct IORequest *CreateExtIO(ioReplyPort,size)
  86.     struct MsgPort *ioReplyPort;
  87.     LONG size;
  88. {
  89.     struct IORequest *ioReq;
  90.  
  91.     if (ioReplyPort == 0)
  92.     return ((struct IORequest   *) 0);
  93.  
  94.     ioReq = AllocMem (size, MEMF_CLEAR | MEMF_PUBLIC);
  95.  
  96.     if (ioReq == 0)
  97.     return ((struct IORequest   *) 0);
  98.  
  99.     ioReq -> io_Message.mn_Node.ln_Type = NT_MESSAGE;
  100.     ioReq -> io_Message.mn_Node.ln_Pri = 0;
  101.  
  102.     ioReq -> io_Message.mn_ReplyPort = ioReplyPort;
  103.  
  104.     return (ioReq);
  105. }
  106.  
  107. /****** exec_support/DeleteExtIO **************************************
  108. *
  109. *   NAME
  110. *    DeleteExtIO() - return memory allocated for extended IO request
  111. *
  112. *   SYNOPSIS
  113. *    DeleteExtIO(ioReq,size);
  114. *
  115. *   FUNCTION
  116. *    See summary line at NAME.  Also frees the signal bit which
  117. *    had been allocated by the call to CreateExtIO.
  118. *
  119. *   INPUTS
  120. *    A pointer to the IORequest block whose resources are to be freed.
  121. *
  122. *   RESULT
  123. *    Frees the memory.  Returns (no error conditions shown)
  124. *
  125. *   EXAMPLE
  126. *    struct IORequest *myBlock;
  127. *    DeleteExtIO(myBlock,(sizeof(struct IOExtTD)));
  128. *        
  129. *    example shows that CreateExtIO had been used to create a trackdisk
  130. *    (extended) IO Request block.
  131. *
  132. *   SEE ALSO
  133. *    CreateExtIO
  134. *
  135. **************************************************************************/
  136.  
  137. DeleteExtIO(ioExt,size)
  138.     struct IORequest *ioExt;
  139.     LONG size;
  140. {
  141.     ioExt -> io_Message.mn_Node.ln_Type = 0xff;
  142.     ioExt -> io_Device = (struct Device *) -1;
  143.     ioExt -> io_Unit = (struct Unit *) -1;
  144.  
  145.     FreeMem (ioExt, size);
  146. }
  147.